﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using OUSMS.AppLogic.BusinessLogicLayer;
using OUSMS.AppLogic.DataAccessLayer;
using OUSMS.Helpers;
namespace OUSMS
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
        }

        protected void okButton_Click(object sender, EventArgs e)
        {
            UsersBLL usersBLL = new UsersBLL();
            Users usersEntity = usersBLL.GetUserByLoginName(loginNameTxtBox.Text.Trim());
            if (usersEntity == null)
            {
                errorMsgLbl.Visible = true;
                errorMsgLbl.Text = "您好，您输入的用户名不存在，请检查信息是否填写正确。";
            }
            else if (!usersEntity.Password.Equals(passwordTxtBox.Text.Trim()))
            {
                errorMsgLbl.Visible = true;
                errorMsgLbl.Text = "您好，您的密码不正确，请重新输入。";
            }
            else if (!(usersEntity.IsApproved.HasValue && usersEntity.IsApproved.Value))
            {
                errorMsgLbl.Visible = true;
                errorMsgLbl.Text = "您的注册申请尚未通过审核，请等待管理员审核。通过之后我们会邮件通知您。";
            }
            else
            {
                FormsAuthentication.SetAuthCookie(usersEntity.LoginName.ToString(), false);
                //进入工作台
                Response.Redirect("WorkCenter.aspx");
            }
        }
    }
}